const express = require('express');
const app = require('./app.js');

console.log('=== 调试路由注册情况 ===');

// 检查app._router.stack中的路由
app._router.stack.forEach((layer, index) => {
  console.log(`Layer ${index}:`);
  
  if (layer.route) {
    console.log(`  Direct route: ${layer.route.path}`);
    console.log(`  Methods: ${Object.keys(layer.route.methods)}`);
  } else if (layer.name === 'router') {
    console.log(`  Router middleware: ${layer.regexp}`);
    console.log(`  Handle type: ${typeof layer.handle}`);
    
    // 尝试获取子路由
    if (layer.handle && layer.handle.stack) {
      console.log(`  Sub-routes count: ${layer.handle.stack.length}`);
      layer.handle.stack.forEach((subLayer, subIndex) => {
        if (subLayer.route) {
          console.log(`    Sub-route ${subIndex}: ${subLayer.route.path}`);
          console.log(`    Methods: ${Object.keys(subLayer.route.methods)}`);
        }
      });
    }
  } else {
    console.log(`  Other middleware: ${layer.name}`);
  }
  console.log('');
});

console.log('=== 测试完成 ===');